import React from 'react'
import {withRouter} from 'react-router-dom'
import { connect } from 'react-redux'
import Cookies from  'js-cookie'

class AuthRoute extends React.Component{

    componentDidMount(){
        console.log(this.props.history)
        const pathname = this.props.location.pathname
        console.log(pathname)
        console.log(Cookies.get('token'))
        if (!Cookies.get('token')){
            console.log('跳转至 login')
            this.props.history.push('/login')

        }else {
            this.props.history.push('/admin/home')
        }
    }

    render(){
        return <div></div>
    }
}
const mapState=(state) => ({
    token:state.getIn(['login', 'token'])
})

const mapDispatch=(dispatch) => ({

})
export default connect(mapState,mapDispatch)(withRouter(AuthRoute))